"""
Form operations
"""
import xlrd
import xlutils.copy
from conf import settings

# 读取
workbook = xlrd.open_workbook(settings.WORKBOOK, formatting_info=True)
table = workbook.sheets()[0]

# 复制写入表
new_workbook = xlutils.copy.copy(workbook)
sheet1 = new_workbook.get_sheet(0)


def read():
    from db.models import Database
    db_list = []
    for i in range(1, table.nrows):
        ip_list = []
        db_list(Database(
            ip_list.append(table.cell_value(i, 4)),
            instance_name=table.cell_value(i, 0),
            instance_rename=table.cell_value(i, 1),
            db_name=table.cell_value(i, 2),
            os_release=table.cell_value(i, 3),
            port=table.cell_value(i, 5),
        ))
    return db_list


def write(host, row):
    pass

def exsit_db_list(db_list):
    for i,db in enumerate(db_list):
        if  db.instance_name =

def excel_save(database, rowx):
    sheet1.write(rowx, 6, database.connect_status)
    sheet1.write(rowx, 7, database.sync_status)
    sheet1.write(rowx, 8, database.account_status)
    sheet1.write(rowx, 9, database.is_bad)
    new_workbook.save(settings.NEW_WORKBOOK)


if __name__ == "__main__":
    print(read())
